#ifndef __RELYER_H__
#define __RELYER_H__

#define BUFSIZE     1024
#define REL_JOBMAX  10000

enum
{
    STATE_R=1,
    STATE_W,
    STATE_Ex,
    STATE_T
};

struct rel_fsm_st
{
    int state;
    int sfd;
    int dfd;
    int pos;
    char buf[BUFSIZE];
    int len;
    char *errstr;
    int64_t count;
};

int fsm_driver(struct rel_fsm_st *fsm);

static void relay(int fd1, int fd2);

enum
{
    STATE_RUNNING = 1,
    STATE_CANCELED,
    STATE_OVER
};

struct rel_stat_st
{
    int state;
    int fd1;
    int fd2;
    int64_t count12, count21;
};

/**
 * @brief 
 * retrun   >= 0            成功，返回当前任务ID
 *          == -EINVAL      失败，参数非法
 *          == -ENOSPC      失败，任务数组满
 *          == -ENOMEM      失败，内存分配有误
 */
int rel_addjob(int fd1, int fd2);

/**
 * @brief 
 * return   == 0            成功，指定任务成功取消
 *          == -EINVAL      失败，参数非法
 *          == -EBUSY       失败，任务早已取消 
 */
int rel_canceljob(int id);

/**
 * @brief 
 * retuen   == 0    成功，指定任务已经终止
 *          == -EINVAL  失败，参数非法
 * 
 */
int rel_waitjob(int id, struct rel_stat_st *);

/**
 * @brief 
 * return   == 0    成功，指定任务状态已经返回
 *          == -EINVAL  失败，参数非法
 * 
 */
int rel_statjob(int id, struct rel_stat_st *);

#endif //__RELYER_H__